package com.neu.yth.nepBackend.role.controller;

import com.neu.yth.nepBackend.entity.SysNode;
import com.neu.yth.nepBackend.role.service.ISysNodeService;
import com.neu.yth.nepBackend.utils.Result;
import org.apache.ibatis.annotations.Param;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * <p>
 * 系统功能节点树 前端控制器
 * </p>
 *
 * @author YTH
 * @since 2024-06-14
 */
@RestController
@RequestMapping("/sysNode")
public class SysNodeController {
    @Autowired
    private ISysNodeService sysNodeService;

    /**
     * 查询所有节点(节点树)
     *
     * @return
     */
    @RequestMapping("select/allTree")
    public Result selectAllTree() {
        return sysNodeService.selectAllTree();
    }

    /**
     * 根据角色id查询节点
     *
     * @param roleId
     * @return
     */
    @RequestMapping("select/{roleId}")
    public Result selectById(@PathVariable Integer roleId) {
        return sysNodeService.selectById(roleId);
    }

    /**
     * 更新节点
     *
     * @param nodes
     * @param roleId
     * @return
     */
    @PutMapping("update/auth/{roleId}")
    public Result update(@PathVariable("roleId") Integer roleId, @RequestBody List<Integer> nodes) {
        System.out.println("nodes:" + nodes);
        System.out.println("roleId:" + roleId);
        if (nodes == null) {
            return Result.fail(500, "nodes为null", null);
        }
        if (roleId == null) {
            return Result.fail(500, "roleId为null", null);
        }
        return sysNodeService.updateNodeById(nodes, roleId);
    }

    /**
     * 根据角色id查询Menu节点
     *
     * @param roleId
     * @return
     */
    @RequestMapping("select/menu/{roleId}")
    public Result selectMenuById(@PathVariable Integer roleId) {
        return sysNodeService.selectMenuById(roleId);
    }


}
